package com.spsoft.vatoutinv.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.enums.ResponseEnum;
import com.spsoft.core.model.Result;
import com.spsoft.vatoutinv.model.dto.vmsiscinformation.VmsIscInformationDto;
import com.spsoft.vatoutinv.model.dto.vmsiscinformation.VmsIscInformationUpOrCancelDto;
import com.spsoft.vatoutinv.model.vo.vmsiscinformation.VmsIscInformationDetailVo;
import com.spsoft.vatoutinv.model.vo.vmsiscinformation.VmsIscInformationVo;
import com.spsoft.vatoutinv.service.vmsiscinformation.VmsIscInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @description: 发票汇总确认信息页签
 * @author: liwm
 * @create: 2024-01-17 16:07
 **/
@RestController
@Api(tags = "发票汇总确认")
@RequestMapping("/vmsIscInformation")
@RequiredArgsConstructor
@Slf4j
@Validated
public class VmsIscInformationController extends BaseController {

    public static final String LOG_MSG = "发票汇总确认控制层";

    private final VmsIscInformationService vmsIscInformationService;

    @ApiOperation("发票汇总确认-本地汇总确认查询")
    @AnonymousAccess(value = "/pageIscConfirm", method = RequestMethod.POST, permissionCode = "VMS_FPHZQR")
    @Log(value = "发票汇总确认-查询汇总确认信息", type = LogActionType.SELECT, menuName = LogMenuEnum.ISC_INFORMATION)
    public Result<VmsIscInformationVo> pageIscConfirm(@RequestBody @Validated  VmsIscInformationDto query) {
        log.info("{}发票汇总确认-查询汇总确认信息，入参：{}", LOG_MSG, JSONObject.toJSONString(query));
        //调用汇总确认信息查询接口
        return vmsIscInformationService.queryIscInformationPage(query);
        //return Result.OK(vmsIscInformationVoResult);
    }
    @ApiOperation("发票汇总确认-乐企确认信息查询")
    @AnonymousAccess(value = "/queryLeqi", method = RequestMethod.POST, permissionCode = "VMS_LeQiQuery")
    @Log(value = "发票汇总确认-乐企确认信息查询", type = LogActionType.SELECT, menuName = LogMenuEnum.ISC_INFORMATION)
    public Result<VmsIscInformationVo> queryLeqi(@RequestBody @Validated  VmsIscInformationDto query) {
        log.info("{}发票汇总确认-乐企确认信息查询，入参：{}", LOG_MSG, JSONObject.toJSONString(query));
        //调用汇总确认信息查询接口
        //return vmsIscInformationService.queryLeqi(query);
        return Result.OK(null);
    }
    @ApiOperation("发票汇总确认-导出发票")
    @AnonymousAccess(value = "/exportExecl", method = RequestMethod.POST, permissionCode = "VMS_ISC_INFORMATION_EXPORT")
    @Log(value = "发票汇总确认-导出发票", type = LogActionType.DOWNLOAD, menuName = LogMenuEnum.ISC_INFORMATION)
    public void exportExcel(@RequestParam String month, HttpServletResponse response) {
        log.info("{}发票汇总确认-导出发票，月份：{}", LOG_MSG, month);
        VmsIscInformationDto query = new VmsIscInformationDto();
        query.setMonth(month);
        vmsIscInformationService.exportExcel(query, response);
    }

    /**
     *   取消汇总确认信息
     *   接口入参“业务类型”选择“1：取消”
     *   选定的汇总月份上传至税局端进行取消汇总确认结果操作，若操作成功则提示，则提示：“取消汇总确认成功！”
     * @param dto
     * @return
     */
    @ApiOperation("发票汇总确认-取消汇总确认")
    @AnonymousAccess(value = "/cancelIsc", method = RequestMethod.POST, permissionCode = "VMS_ISC_INFORMATION_CANCEL")
    @Log(value = "发票汇总确认-取消汇总确认", type = LogActionType.SEND, menuName = LogMenuEnum.ISC_INFORMATION)
    public Result cancelIsc(@RequestBody VmsIscInformationUpOrCancelDto dto) {
        log.info("{}发票汇总确认-取消汇总确认，入参：{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsIscInformationService.cancelIscInforUpload(dto);
    }

    /**
     * 汇总确认信息，调用乐企接口
     * 接口入参“业务类型”选择“0：确认”，将选定的汇总月份、发票汇总确认信息上传至税局端进行汇总结果比对
     * 若比对一致，则提示：“汇总确认成功！”
     * @param dto
     * @return
     */
    @ApiOperation("发票汇总确认-上传汇总确认信息")
    @AnonymousAccess(value = "/uploadIsc", method = RequestMethod.POST, permissionCode = "VMS_ISC_INFORMATION_UPLOAD")
    @Log(value = "发票汇总确认-上传汇总确认信息", type = LogActionType.SEND, menuName = LogMenuEnum.ISC_INFORMATION)
    public Result uploadIsc(@RequestBody VmsIscInformationUpOrCancelDto dto) {
        log.info("{}发票汇总确认-上传汇总确认信息，入参：{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsIscInformationService.uploadIscInfor(dto);
    }

    @ApiOperation("查询发票信息")
    @AnonymousAccess(value = "/pageInvoice", method = RequestMethod.POST, permissionCode = "VMS_FPHZQR")
    @Log(value = "查询发票信息", type = LogActionType.SELECT, menuName = LogMenuEnum.ISC_INFORMATION)
    public Result<IPage<VmsIscInformationDetailVo>> pageInvoice(@RequestBody @Validated  VmsIscInformationDto query) {
        log.info("{}查询发票信息，入参：{}", LOG_MSG, JSONObject.toJSONString(query));
        // 调用发票明细查询接口
        IPage<VmsIscInformationDetailVo> iPageResult = vmsIscInformationService.queryIscInformationDetailPage(query);
        return Result.OK(iPageResult);
    }

}
